package core.battle
{
	public class SpaceShipObject extends GameObject
	{
		
		private var _speed : Number;
		private var _acceleration : Number;
		private var _color :uint = 0x14C5D5;
		
		private static const _GRAVITY :Number = 5e-5;
		private static const _POWER : Number = 10e-5;
		
		public function SpaceShipObject()
		{
			super();
		}
		
		public function setPower( isOn : Boolean ) : void {
			if( isOn ) {
				_acceleration = _GRAVITY - _POWER;
			} else {
				_acceleration = _GRAVITY;
			}
		}
		
		public function setDefault() : void {
			x = Game.WIDTH * (1-0.618);
			y = Game.HEIGHT * 0.5;
			this.rotationZ = 0;
			_speed = 0;
			_acceleration = _GRAVITY;
		}
		
		private var _size :Number = 4;
		override public function init():void {
			graphics.lineStyle( 2 , _color );
			graphics.moveTo( - _size , _size );
			graphics.lineTo( _size , 0 );
			graphics.lineTo( -_size , -_size );
			graphics.lineTo( -_size, _size);
			setDefault();
		}
		
		override public function dispose():void{
		}
		
		override public function update(deltaTime:Number):void {
			super.update( deltaTime );

			if( Game.getInstance().mousePressed ) {
				setPower(true);
			} else {
				setPower( false );
			}
			if( !isIn() ) {
				setDefault();
			}
			
			this.rotationZ = Math.atan( _speed / Game.getInstance().forwardSpeed ) * 180 / Math.PI;
			
			trace( "_speed: " + _speed );
			trace( "forwardSpeed: " + Game.getInstance().forwardSpeed );
			trace( "rotZ : " + this.rotationZ );
			
			y += _speed * deltaTime;
			_speed += _acceleration * deltaTime;
		}
	}
}